package cn.elves.model.auth.controller;


import cn.elves.model.auth.entity.dto.AuthenticationDTO;
import cn.elves.model.auth.entity.dto.RoleDTO;
import cn.elves.model.auth.service.AuthenticationService;
import cn.elves.model.entity.dto.response.ResponseDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
public class AuthenticationController {

    @Resource
    private AuthenticationService authenticationService;

    @GetMapping("auth/availableMenu")
    public ResponseDTO<AuthenticationDTO> getAvailableMenu(@RequestParam("userId") Long userId) {
        return ResponseDTO.success(authenticationService.selectAvailableMenu(userId));
    }

    @GetMapping("auth/isAvailableInterface")
    public ResponseDTO<Boolean> decideInterfaceAvailable(@RequestParam("userId") Long userId,
                                                     @RequestParam("url") String url,
                                                     @RequestParam("method") String method) {
        return ResponseDTO.success(authenticationService.decideInterfaceAvailable(userId,url,method));
    }

    @GetMapping("auth/roles")
    public ResponseDTO<Set<RoleDTO>> queryRoleByUserId(@RequestParam("userId") String userId) {
        return ResponseDTO.success(authenticationService.queryRoleByUserId(userId));
    }
}
